home *** CD-ROM | disk | FTP | other *** search
- program RobotFTP;
- {$I+}
- {$APPTYPE CONSOLE}
- uses
- Windows, WinINet, SysUtils, DrBobCGI, DrBobUUE, DrBobEml;
-
- procedure CopyURL(const URL, OutputFile: String);
- const
- BufferSize = 8 * 1024;
- var
- hSession, hURL: HInternet;
- Buffer: array[0..Pred(BufferSize)] of Byte;
- BufferLength: DWORD;
- i: Integer;
- f: File;
- begin
- hSession := InternetOpen('DrBob',INTERNET_OPEN_TYPE_PRECONFIG,nil,nil,0);
- try
- hURL := InternetOpenURL(hSession, PChar(URL), nil,0,0,0);
- try
- Assign(f, OutputFile);
- Rewrite(f,1);
- writeln('Downloading...<P>');
- i := 0;
- repeat
- InternetReadFile(hURL, @Buffer, BufferSize, BufferLength);
- inc(i);
- if (i in [1,2,4,8,16,32,64]) or (i mod 64 = 0) then
- writeln(i*8,'KBytes...<BR>');
- BlockWrite(f, Buffer, BufferLength)
- until BufferLength < BufferSize;
- Close(f);
- writeln('<BR>',(i-1)*BufferSize + BufferLength,' Bytes downloaded.');
- finally
- InternetCloseHandle(hURL)
- end
- finally;
- InternetCloseHandle(hSession)
- end
- end;
-
- var
- f: Text;
- Str: String;
- counter: Integer;
- begin
- ShortDateFormat := 'YYYY/MM/DD';
- writeln('content-type: text/html');
- writeln;
- writeln('<HTML>');
- writeln('<HEAD>');
- writeln('<TITLE>',Value('URL'),' -> ',Value('File'),'</TITLE>');
- writeln('</HEAD>');
- writeln('<BODY BACKGROUND="/gif/back.gif">');
- writeln('<H1>RobotBob/FTP v1.0</H1>');
- writeln('<HR>');
- writeln('<BR>URL=',Value('URL'));
- writeln('<BR>File=',Value('File'));
- writeln('<BR>Mail=',Value('Mail'));
- writeln('<P>');
- ChDir('RobotBob'); { place to leave FTP-files }
- {$I-}
- Assign(f,'robotbob.log');
- Reset(f);
- counter := 0;
- if IOResult = 0 then while not eof(f) do
- begin
- readln(f);
- Inc(counter)
- end
- else Rewrite(f);
- if IOResult <> 0 then { skip };
- Append(f);
- Inc(counter);
- writeln(f,counter:4,': ',Value('URL'),' -> ',Value('File'),' to ',Value('Mail'));
- Close(f);
- if IOResult <> 0 then { skip };
- writeln('Request #',counter,' at ',DateTimeToStr(Now),'<P>');
- {$I+}
- ChDir('FTP');
- if (Value('URL') <> '') and (Value('File') <> '') then
- begin
- CopyURL(Value('URL'), ExtractFileName(Value('File')));
- if Value('Mail') <> '' then
- begin
- with TBUUCode.Create(nil) do
- try
- InputFile := ExtractFileName(Value('File'));
- Str := InputFile;
- if Pos('.',Str) > 0 then Delete(Str,Pos('.',Str),255);
- if Str = '' then Str := 'output';
- OutputFile := Str + '.uue';
- Algorithm := uuencode;
- try
- UUCode;
- with TBSMTP.Create(nil) do
- try
- MailServer := 'smtp.server.com';
- MessageFrom := 'RobotBob';
- MessageTo := Value('Mail');
- MessageSubject := 'Automatic E-mail using SMTP';
- MessageText.Add('Hi '+Value('Mail')+',');
- MessageText.Add('');
- MessageText.Add('URL='+Value('URL'));
- MessageText.Add('File='+Value('File'));
- MessageText.Add('UUCode='+OutputFile);
- MessageText.Add('Mail='+Value('Mail'));
- MessageText.Add('');
- System.Assign(f,OutputFile);
- Reset(f);
- while not eof(f) do
- begin
- readln(f,Str);
- MessageText.Add(Str)
- end;
- System.Close(f);
- Erase(f);
- MessageText.Add('');
- MessageText.Add('Groetjes,');
- MessageText.Add(' RobotBob - RobotBob@drbob42.com');
- writeln('<P>Sending mail to ',Value('Mail'),'...');
- SendMail;
- writeln('<P>Sent.');
- finally
- Free
- end
- except
- on E: Exception do
- writeln(E.Message)
- end
- finally
- writeln('<P>Done.');
- Free
- end
- end
- end;
- writeln('</BODY>');
- writeln('</HTML>')
- end.
-